#!/bin/bash
# Debian 13 (Trixie) AnyDesk 一键安装脚本
# 作者: Major Guo
# 仓库: https://gitee.com/你的用户名/debian13-anydesk

set -e

echo "=== 更新系统并安装依赖工具 ==="
sudo apt update
sudo apt install -y ca-certificates curl gnupg

echo "=== 添加 AnyDesk GPG 密钥 ==="
sudo mkdir -p /usr/share/keyrings
curl -fsSL https://keys.anydesk.com/repos/DEB-GPG-KEY \
  | gpg --dearmor \
  | sudo tee /usr/share/keyrings/anydesk.gpg > /dev/null

echo "=== 添加 AnyDesk APT 软件源 ==="
echo "deb [signed-by=/usr/share/keyrings/anydesk.gpg] https://deb.anydesk.com/ all main" \
  | sudo tee /etc/apt/sources.list.d/anydesk-stable.list > /dev/null

echo "=== 更新 APT 索引 ==="
sudo apt update

echo "=== 开始安装 AnyDesk ==="
if ! sudo apt install -y anydesk; then
  echo "!!! 安装失败，尝试修复依赖并重试..."
  sudo apt --fix-broken install -y
  sudo apt install -y anydesk
fi

echo "=== AnyDesk 安装完成！==="
echo "运行 'anydesk' 即可启动，或在桌面菜单中查找 AnyDesk。"
